package uttype

import (
	"strconv"
	"strings"
)

const (
	StrSpe1 = "|"
	StrSpe2 = "_"
)

func StringToInt(str string) int {
	if value, err := strconv.Atoi(str); err == nil {
		return value
	}
	return 0
}
func StringToInt32(str string) int32 {
	return int32(StringToInt(str))
}
func StringToInt64(str string) int64 {
	if value, err := strconv.ParseInt(str, 10, 64); err == nil {
		return value
	}
	return 0
}
func IntToString(value int) string {
	return strconv.Itoa(value)
}
func Int32ToString(value int32) string {
	return IntToString(int(value))
}
func Int64ToString(value int64) string {
	return strconv.FormatInt(value, 10)
}

func ListStringToListInt(list []string) []int {
	result := make([]int, 0)
	for _, v := range list {
		result = append(result, StringToInt(v))
	}
	return result
}
func ListStringToListInt64(list []string) []int64 {
	result := make([]int64, 0)
	for _, v := range list {
		result = append(result, StringToInt64(v))
	}
	return result
}
func StringToListString(str string) []string {
	return strings.Split(str, StrSpe1)
}
func StringToListInt(str string) []int {
	return ListStringToListInt(strings.Split(str, StrSpe1))
}
func StringToListListString(str string) [][]string {
	result := make([][]string, 0)
	list1 := strings.Split(str, StrSpe1)
	for _, v := range list1 {
		list2 := strings.Split(v, StrSpe2)
		result = append(result, list2)
	}
	return result
}
func StringToListListInt(str string) [][]int {
	result := make([][]int, 0)
	list1 := strings.Split(str, StrSpe1)
	for _, v := range list1 {
		list2 := strings.Split(v, StrSpe2)
		result = append(result, ListStringToListInt(list2))
	}
	return result
}
func StringToListListInt64(str string) [][]int64 {
	result := make([][]int64, 0)
	list1 := strings.Split(str, StrSpe1)
	for _, v := range list1 {
		list2 := strings.Split(v, StrSpe2)
		result = append(result, ListStringToListInt64(list2))
	}
	return result
}
